// store 仓库的意思
//1. 导入 createStore   创建仓库的意思
import {createStore, applyMiddleware, combineReducers} from 'redux';
//导入 thunk 中间件
import thunk from 'redux-thunk';
import countReducer from './reducers/countReducer';
import zanReducer from './reducers/zanReducer';
import todoReducer from './reducers/todoReducer';
//导入 redux 开发者工具的扩展包
import {composeWithDevTools} from 'redux-devtools-extension';
import { asyncGetTodos } from './reducers/todoReducer';
//合并 reducer. 合并 reducer 之后, redux 内部保存的状态值就会称为一个『对象』
let reducer = combineReducers({
  count: countReducer,
  zan: zanReducer,
  todo: todoReducer
});

//2. 创建 store 对象    reducer 函数(加工厂函数)
//该回调是一个同步回调, 该回调在将来更新状态时也会执行, 该函数的执行返回值, 将会用来去更新内部状态
// action 动作, 值是一个对象, 用来描述对状态的操作, type 类型 payload 数据  (payload 载荷的意思) 
// {type: 'add', payload: 1}
// {type: 'sub', payload: 10}
let store = createStore(reducer, composeWithDevTools({trace: true})(applyMiddleware(thunk)));

//测试 asyncGetTodos
// store.dispatch(asyncGetTodos());

//默认暴露 store
export default store;


